package com.zust.ysc012.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

import static com.zust.ysc012.service.EnterService.getSign;
import static com.zust.ysc012.service.EnterService.isRegister;

@WebServlet(urlPatterns = "/registerServlet")
public class RegisterServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        super.init();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        try {
            String account = req.getParameter("account");
            String password = req.getParameter("password");
            HttpSession session = req.getSession(true);
//            int i = getSign(account);
//            session.setAttribute("sign", i);
//            session.setAttribute("account", account);
            if (isRegister(account, password)) {
                req.getRequestDispatcher("/WEB-INF/notice.jsp").forward(req,resp);
            } else {
                //记得扩充
                System.out.println("错误");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
